home *** CD-ROM | disk | FTP | other *** search
- package icontrols.RichText;
-
- import com.ms.dll.DllLib;
- import com.ms.wd.app.Message;
- import com.ms.wd.core.Component;
- import com.ms.wd.core.Event;
- import com.ms.wd.core.EventHandler;
- import com.ms.wd.io.ByteStream;
- import com.ms.wd.io.File;
- import com.ms.wd.io.IDataStream;
- import com.ms.wd.ui.Color;
- import com.ms.wd.ui.Control;
- import com.ms.wd.ui.CreateParams;
- import com.ms.wd.util.Debug;
- import com.ms.wd.util.Root;
- import com.ms.wd.win32.DEVMODE;
- import com.ms.wd.win32.NMHDR;
- import com.ms.wd.win32.Util;
- import com.ms.wd.win32.Windows;
-
- public class RichText extends Control {
- public static final int SB_NONE = 0;
- public static final int SB_ASNEEDED = 1;
- public static final int SB_FORCED = 2;
- public static final int ALIGN_MULTI = -1;
- public static final int ALIGN_LEFT = 0;
- public static final int ALIGN_RIGHT = 1;
- public static final int ALIGN_CENTER = 2;
- public static final int ATTRIBUTE_MIX = -1;
- public static final int ATTRIBUTE_NONE = 0;
- public static final int ATTRIBUTE_ALL = 1;
- public static final int WHOLEWORD = 2;
- public static final int MATCHCASE = 4;
- public static final int NOHIGHLIGHT = 8;
- public static final int RICHTEXT_FILE = 0;
- public static final int PLAINTEXT_FILE = 1;
- static final int INPUT = 0;
- static final int OUTPUT = 1;
- private static final Module mod = new Module();
- private static final String NOT_SUPPORTED = "Not supported at Design time";
- private static final String SZ_RTF_TAG = "{\\rtf";
- private static final int CHAR_BUFFER_LEN = 512;
- private static final Object EVENT_HSCROLL = new Object();
- private static final Object EVENT_PROTECTED = new Object();
- private static final Object EVENT_SELCHANGE = new Object();
- private static final Object EVENT_VSCROLL = new Object();
- private int bulletIndent = 0;
- private String fileName = null;
- private int hDC = 0;
- private int maxLength = 0;
- private int rightMargin = 0;
- private int scrollBars = 1;
- private int style = 32964;
- private boolean wantTabs = true;
- transient IDataStream bis = null;
- transient IDataStream bos = null;
- private transient int editStreamProcRoot = 0;
- private transient boolean protectedError = false;
- // $FF: synthetic field
- private static Class class$com$ms$wd$win32$NMHDR;
- // $FF: synthetic field
- private static Class class$icontrols$RichText$ENDROPFILES;
- // $FF: synthetic field
- private static Class class$icontrols$RichText$ENPROTECTED;
- // $FF: synthetic field
- private static Class class$icontrols$RichText$CHARFORMAT;
-
- public int getSelBold() {
- return this.getCharFormat(1, 1);
- }
-
- public EventHandler getOnHScroll() {
- return (EventHandler)((Component)this).getEventHandler(EVENT_HSCROLL);
- }
-
- public EventHandler getOnVScroll() {
- return (EventHandler)((Component)this).getEventHandler(EVENT_VSCROLL);
- }
-
- protected void onHScroll(Event e) {
- ((Component)this).fireEvent(EVENT_HSCROLL, e);
- }
-
- protected void onVScroll(Event e) {
- ((Component)this).fireEvent(EVENT_VSCROLL, e);
- }
-
- public String getSelFontName() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- String selFontName = null;
- if (((Control)this).isHandleCreated()) {
- CHARFORMAT cf = new CHARFORMAT();
- this.sendMessage(1082, true, cf);
- if ((cf.dwMask & 536870912) != 0) {
- selFontName = new String(cf.szFaceName);
- }
- }
-
- return selFontName;
- }
- }
-
- public void setSelBold(int selBold) {
- this.setCharFormat(1, 1, selBold);
- }
-
- public void setSelFontName(String selFontName) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- CHARFORMAT cf = new CHARFORMAT();
- cf.dwMask = 536870912;
- int count = Math.min(selFontName.length(), 32);
- selFontName.getChars(0, count - 1, cf.szFaceName, 0);
- this.sendMessage(1092, 1, (CHARFORMAT)cf);
- }
-
- }
- }
-
- public void setSelStart(int selStart) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- CHARRANGE range = new CHARRANGE();
- range.cpMax = range.cpMin = selStart;
- this.sendMessage(1079, 0, (CHARRANGE)range);
- this.sendMessage(183);
- }
-
- }
- }
-
- public void setMultiLine(boolean multiLine) {
- if (multiLine && (this.style & 4) == 0 || !multiLine && (this.style & 4) != 0) {
- this.style = multiLine ? this.style | 4 : this.style & -5;
- if (!((Component)this).isDesignMode() && ((Control)this).isHandleCreated()) {
- ((Control)this).recreateHandle();
- }
- }
-
- }
-
- public void setText(String text) {
- if (((Control)this).isHandleCreated()) {
- this.streamIn(text, 1);
- }
-
- }
-
- public void setWantTabs(boolean wantTabs) {
- this.wantTabs = wantTabs;
- }
-
- private boolean isCharInCharSet(char c, String charSet, boolean negate) {
- boolean match = false;
- int charSetLen = charSet.length();
-
- for(int i = 0; !match && i < charSetLen; ++i) {
- match = c == charSet.charAt(i);
- }
-
- if (negate) {
- return !match;
- } else {
- return match;
- }
- }
-
- protected CreateParams getCreateParams() {
- CreateParams cp = super.getCreateParams();
- cp.className = "RICHEDIT";
- cp.style &= -1;
- cp.style |= this.style;
- if (this.scrollBars == 1) {
- cp.style |= 3145728;
- } else if (this.scrollBars == 2) {
- cp.style |= 3153920;
- }
-
- cp.exStyle |= 512;
- return cp;
- }
-
- public void addOnSelChange(EventHandler value) {
- ((Component)this).addEventHandler(EVENT_SELCHANGE, value);
- }
-
- protected int sendMessage(int msg) {
- return Windows.SendMessage(((Control)this).getHandle(), msg, 0, 0);
- }
-
- protected int sendMessage(int msg, boolean wParam) {
- return RichEdit.SendMessage(((Control)this).getHandle(), msg, wParam, 0);
- }
-
- protected int sendMessage(int msg, boolean wParam, boolean lParam) {
- return RichEdit.SendMessage(((Control)this).getHandle(), msg, wParam, lParam);
- }
-
- protected int sendMessage(int msg, boolean wParam, CHARFORMAT lParam) {
- return RichEdit.SendMessage(((Control)this).getHandle(), msg, wParam, lParam);
- }
-
- protected int sendMessage(int msg, boolean wParam, int lParam) {
- return RichEdit.SendMessage(((Control)this).getHandle(), msg, wParam, lParam);
- }
-
- public int getSelAlignment() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int selAlignment = 0;
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- this.sendMessage(1085, 0, (PARAFORMAT)pf);
- if ((8 & pf.dwMask) != 0) {
- switch (pf.wAlignment) {
- case 1:
- selAlignment = 0;
- break;
- case 2:
- selAlignment = 1;
- break;
- case 3:
- selAlignment = 2;
- break;
- default:
- Debug.assert(false, "RichText - getSelAlignment: Unknown PFA alignment type");
- }
- }
- }
-
- return selAlignment;
- }
- }
-
- public int getSelHangingIndent() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int selHangingIndent = 0;
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- this.sendMessage(1085, 0, (PARAFORMAT)pf);
- if ((4 & pf.dwMask) != 0) {
- selHangingIndent = pf.dxOffset;
- }
- }
-
- return selHangingIndent;
- }
- }
-
- public int getSelIndent() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int selIndent = 0;
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- this.sendMessage(1085, 0, (PARAFORMAT)pf);
- if ((1 & pf.dwMask) != 0) {
- selIndent = pf.dxStartIndent;
- }
- }
-
- return selIndent;
- }
- }
-
- public int getSelRightIndent() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int selRightIndent = 0;
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- this.sendMessage(1085, 0, (PARAFORMAT)pf);
- if ((2 & pf.dwMask) != 0) {
- selRightIndent = pf.dxRightIndent;
- }
- }
-
- return selRightIndent;
- }
- }
-
- protected int sendMessage(int msg, int wParam, CHARFORMAT lParam) {
- return RichEdit.SendMessage(((Control)this).getHandle(), msg, wParam, lParam);
- }
-
- protected int sendMessage(int msg, int wParam, CHARRANGE lParam) {
- return RichEdit.SendMessage(((Control)this).getHandle(), msg, wParam, lParam);
- }
-
- protected int sendMessage(int msg, int wParam, EDITSTREAM lParam) {
- return RichEdit.SendMessage(((Control)this).getHandle(), msg, wParam, lParam);
- }
-
- protected int sendMessage(int msg, int wParam, FINDTEXT lParam) {
- return RichEdit.SendMessage(((Control)this).getHandle(), msg, wParam, lParam);
- }
-
- protected int sendMessage(int msg, int wParam, PARAFORMAT lParam) {
- return RichEdit.SendMessage(((Control)this).getHandle(), msg, wParam, lParam);
- }
-
- protected int sendMessage(int msg, int wParam, TEXTRANGE lParam) {
- return RichEdit.SendMessage(((Control)this).getHandle(), msg, wParam, lParam);
- }
-
- public void setSelAlignment(int selAlignment) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- pf.dwMask = 8;
- switch (selAlignment) {
- case 0:
- pf.wAlignment = 1;
- break;
- case 1:
- pf.wAlignment = 2;
- break;
- case 2:
- pf.wAlignment = 3;
- break;
- default:
- throw new IllegalArgumentException("setSelAlignment: Unknown selAlignment type");
- }
-
- this.sendMessage(1095, 0, (PARAFORMAT)pf);
- }
-
- }
- }
-
- public void setSelHangingIndent(int selHangingIndent) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- pf.dwMask = 4;
- pf.dxOffset = selHangingIndent;
- this.sendMessage(1095, 0, (PARAFORMAT)pf);
- }
-
- }
- }
-
- public void setSelIndent(int selIndent) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- pf.dwMask = 1;
- pf.dxStartIndent = selIndent;
- this.sendMessage(1095, 0, (PARAFORMAT)pf);
- }
-
- }
- }
-
- public void setSelRightIndent(int selRightIndent) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- pf.dwMask = 2;
- pf.dxRightIndent = selRightIndent;
- this.sendMessage(1095, 0, (PARAFORMAT)pf);
- }
-
- }
- }
-
- public int getLineFromChar(int charPos) {
- return ((Control)this).sendMessage(1078, 0, charPos);
- }
-
- public void upTo(String characterSet) {
- this.spanUpTo(characterSet, true, false, false);
- }
-
- public void upTo(String characterSet, boolean forward) {
- this.spanUpTo(characterSet, forward, false, false);
- }
-
- public void upTo(String characterSet, boolean forward, boolean negate) {
- this.spanUpTo(characterSet, forward, negate, false);
- }
-
- public void setReadOnly(boolean readOnly) {
- this.style = readOnly ? this.style | 2048 : this.style & -2049;
- if (!((Component)this).isDesignMode() && ((Control)this).isHandleCreated()) {
- this.sendMessage(207, readOnly, 0);
- }
-
- }
-
- public int getSelStrikeThru() {
- return this.getCharFormat(8, 8);
- }
-
- public void setSelStrikeThru(int selStrikeThru) {
- this.setCharFormat(8, 8, selStrikeThru);
- }
-
- public int getSelBullet() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int selBullet = 0;
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- this.sendMessage(1085, 0, (PARAFORMAT)pf);
- if ((32 & pf.dwMask) != 0 && 1 == pf.wNumbering) {
- selBullet = 1;
- }
- }
-
- return selBullet;
- }
- }
-
- public void setSelBullet(int selBullet) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- pf.dwMask = 36;
- switch (selBullet) {
- case 0:
- pf.wNumbering = 0;
- pf.dxOffset = 0;
- break;
- case 1:
- pf.wNumbering = 1;
- pf.dxOffset = this.bulletIndent;
- break;
- default:
- throw new IllegalArgumentException("setSelBullet: Unknown selBullet type");
- }
-
- this.sendMessage(1095, 0, (PARAFORMAT)pf);
- }
-
- }
- }
-
- public int getSelUnderline() {
- return this.getCharFormat(4, 4);
- }
-
- public boolean isMultiLine() {
- return (this.style & 4) != 0;
- }
-
- public void setSelUnderline(int selUnderline) {
- this.setCharFormat(4, 4, selUnderline);
- }
-
- void wmReflectNotify(Message m) {
- if (m.hWnd == ((Control)this).getHandle()) {
- NMHDR nmhdr = (NMHDR)DllLib.ptrToStruct(class$com$ms$wd$win32$NMHDR != null ? class$com$ms$wd$win32$NMHDR : (class$com$ms$wd$win32$NMHDR = class$("com.ms.wd.win32.NMHDR")), m.lParam);
- switch (nmhdr.code) {
- case 1794:
- this.onSelChange(Event.EMPTY);
- break;
- case 1795:
- ENDROPFILES endropfiles = (ENDROPFILES)DllLib.ptrToStruct(class$icontrols$RichText$ENDROPFILES != null ? class$icontrols$RichText$ENDROPFILES : (class$icontrols$RichText$ENDROPFILES = class$("icontrols.RichText.ENDROPFILES")), m.lParam);
- StringBuffer path = new StringBuffer(260);
- DragQueryFile(endropfiles.hDrop, 0, path, 260);
-
- try {
- this.loadFile(path.toString(), 0);
- } catch (Exception var8) {
- try {
- this.loadFile(path.toString(), 1);
- } catch (Exception var7) {
- }
- }
-
- m.result = 1;
- break;
- case 1796:
- ENPROTECTED enprotected = (ENPROTECTED)DllLib.ptrToStruct(class$icontrols$RichText$ENPROTECTED != null ? class$icontrols$RichText$ENPROTECTED : (class$icontrols$RichText$ENPROTECTED = class$("icontrols.RichText.ENPROTECTED")), m.lParam);
- switch (enprotected.msg) {
- case 12:
- case 1077:
- m.result = 0;
- return;
- case 194:
- case 1095:
- break;
- case 770:
- m.result = 1;
- return;
- case 1092:
- CHARFORMAT charFormat = (CHARFORMAT)DllLib.ptrToStruct(class$icontrols$RichText$CHARFORMAT != null ? class$icontrols$RichText$CHARFORMAT : (class$icontrols$RichText$CHARFORMAT = class$("icontrols.RichText.CHARFORMAT")), m.lParam);
- if ((charFormat.dwMask & 16) != 0) {
- m.result = 0;
- return;
- }
- break;
- case 1097:
- if ((enprotected.wParam & 'ΦÇÇ') == 0) {
- m.result = 0;
- return;
- }
- break;
- default:
- Windows.MessageBeep(0);
- m.result = 1;
- return;
- }
-
- this.onProtected(Event.EMPTY);
- m.result = 1;
- break;
- default:
- super.wndProc(m);
- }
- } else {
- super.wndProc(m);
- }
-
- }
-
- public int getSelCharOffset() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int selCharOffset = 0;
- if (((Control)this).isHandleCreated()) {
- CHARFORMAT cf = new CHARFORMAT();
- this.sendMessage(1082, true, cf);
- if ((cf.dwMask & 268435456) != 0) {
- selCharOffset = cf.yOffset;
- }
- }
-
- return selCharOffset;
- }
- }
-
- public void setSelCharOffset(int selCharOffset) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- CHARFORMAT cf = new CHARFORMAT();
- cf.dwMask = 268435456;
- cf.yOffset = selCharOffset;
- this.sendMessage(1092, 1, (CHARFORMAT)cf);
- }
-
- }
- }
-
- public int[] getSelTabs() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int[] selTabs = null;
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- this.sendMessage(1085, 0, (PARAFORMAT)pf);
- if ((16 & pf.dwMask) != 0) {
- selTabs = new int[pf.cTabCount];
-
- for(int x = 0; x < pf.cTabCount; ++x) {
- selTabs[x] = pf.rgxTabs[x];
- }
- }
- }
-
- return selTabs;
- }
- }
-
- public boolean isWantTabs() {
- return this.wantTabs;
- }
-
- public void setSelTabs(int[] selTabs) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- this.sendMessage(1085, 0, (PARAFORMAT)pf);
- pf.dwMask = 16;
-
- for(int x = 0; x < pf.cTabCount; ++x) {
- pf.rgxTabs[x] = selTabs[x];
- }
-
- this.sendMessage(1095, 0, (PARAFORMAT)pf);
- }
-
- }
- }
-
- // $FF: synthetic method
- private static Class class$(String s) {
- try {
- return Class.forName(s);
- } catch (ClassNotFoundException e) {
- throw new NoClassDefFoundError(((Throwable)e).getMessage());
- }
- }
-
- public void setHideSelection(boolean hideSelection) {
- this.style = hideSelection ? this.style | 256 : this.style & -257;
- if (!((Component)this).isDesignMode() && ((Control)this).isHandleCreated()) {
- this.sendMessage(1087, hideSelection, true);
- }
-
- }
-
- public void dispose() {
- if (this.hDC != 0) {
- Windows.DeleteDC(this.hDC);
- }
-
- super.dispose();
- }
-
- public void selPrint() {
- throw new RuntimeException("selPrint: Not Implemented.");
- }
-
- public void addOnProtected(EventHandler value) {
- ((Component)this).addEventHandler(EVENT_PROTECTED, value);
- }
-
- public int find(String string) {
- return this.find(string, 0, -1, 0);
- }
-
- public int find(String string, int options) {
- return this.find(string, 0, -1, options);
- }
-
- public int find(String string, int start, int options) {
- return this.find(string, start, -1, options);
- }
-
- public int find(String string, int start, int end, int options) {
- boolean selectWord = true;
- FINDTEXT ft = new FINDTEXT();
- int findOptions = 0;
- ft.lpstrText = string;
- if (start < 0) {
- this.sendMessage(1076, 0, (CHARRANGE)ft.chrg);
- } else {
- if (start > 0) {
- ft.chrg.cpMin = start;
- } else {
- ft.chrg.cpMin = 0;
- }
-
- if (end >= 0) {
- ft.chrg.cpMax = end;
- } else {
- ft.chrg.cpMax = -1;
- }
- }
-
- if (ft.chrg.cpMin == ft.chrg.cpMax) {
- ft.chrg.cpMin = 0;
- ft.chrg.cpMax = -1;
- }
-
- if ((options & 2) != 0) {
- findOptions |= 2;
- }
-
- if ((options & 4) != 0) {
- findOptions |= 4;
- }
-
- if ((options & 8) != 0) {
- selectWord = false;
- }
-
- int position = this.sendMessage(1080, findOptions, (FINDTEXT)ft);
- if (position != -1 || !selectWord) {
- CHARRANGE chrg = new CHARRANGE();
- chrg.cpMin = position;
- chrg.cpMax = position + string.length();
- this.sendMessage(1079, 0, (CHARRANGE)chrg);
- this.sendMessage(183);
- }
-
- return position;
- }
-
- public Color getSelColor() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- Color selColor = new Color(Windows.GetSysColor(8));
- if (((Control)this).isHandleCreated()) {
- CHARFORMAT cf = new CHARFORMAT();
- this.sendMessage(1082, true, cf);
- if ((cf.dwMask & 1073741824) != 0) {
- selColor = new Color(cf.crTextColor);
- }
- }
-
- return selColor;
- }
- }
-
- private boolean isProtectedError() {
- if (this.protectedError) {
- this.protectedError = false;
- return true;
- } else {
- return false;
- }
- }
-
- public void setSelColor(Color selColor) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- CHARFORMAT cf = new CHARFORMAT();
- cf.dwMask = 1073741824;
- cf.crTextColor = selColor.getRGB();
- this.sendMessage(1092, 1, (CHARFORMAT)cf);
- }
-
- }
- }
-
- public boolean isHideSelection() {
- return (this.style & 256) == 0;
- }
-
- public void setWantReturns(boolean wantReturns) {
- this.style = wantReturns ? this.style | 4096 : this.style & -4097;
- if (!((Component)this).isDesignMode() && ((Control)this).isHandleCreated()) {
- ((Control)this).sendMessage(1101, 2, 4096);
- }
-
- }
-
- public int getSelFontSize() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int selFontSize = 0;
- if (((Control)this).isHandleCreated()) {
- CHARFORMAT cf = new CHARFORMAT();
- this.sendMessage(1082, true, cf);
- if ((cf.dwMask & Integer.MIN_VALUE) != 0) {
- selFontSize = cf.yHeight;
- }
- }
-
- return selFontSize;
- }
- }
-
- public void setSelFontSize(int selFontSize) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- CHARFORMAT cf = new CHARFORMAT();
- cf.dwMask = Integer.MIN_VALUE;
- cf.yHeight = selFontSize;
- this.sendMessage(1092, 1, (CHARFORMAT)cf);
- }
-
- }
- }
-
- private void spanUpTo(String characterSet, boolean forward, boolean negate, boolean span) {
- if (characterSet.length() != 0) {
- CHARRANGE chrg = new CHARRANGE();
- this.sendMessage(1076, 0, (CHARRANGE)chrg);
- CHARRANGE chrgSave = new CHARRANGE();
- chrgSave.cpMin = chrg.cpMin;
- chrgSave.cpMax = chrg.cpMax;
- chrg.cpMax = chrg.cpMin;
- TEXTRANGE txrg = new TEXTRANGE();
- txrg.chrg.cpMin = chrg.cpMin;
- txrg.chrg.cpMax = chrg.cpMax;
- CharBuffer charBuffer = CharBuffer.createBuffer(513);
- txrg.lpstrText = charBuffer.allocCoTaskMem();
- if (txrg.lpstrText == 0) {
- throw new RuntimeException("spanUpTo: Unable to get memory.");
- } else {
- boolean done = false;
-
- while(!done) {
- if (forward) {
- txrg.chrg.cpMin = chrg.cpMax;
- CHARRANGE var10000 = txrg.chrg;
- var10000.cpMax += 512;
- } else {
- txrg.chrg.cpMax = chrg.cpMin;
- CHARRANGE var16 = txrg.chrg;
- var16.cpMin -= 512;
- if (txrg.chrg.cpMin < 0) {
- txrg.chrg.cpMin = 0;
- }
- }
-
- int len = this.sendMessage(1099, 0, (TEXTRANGE)txrg);
- if (len == 0) {
- break;
- }
-
- charBuffer.putCoTaskMem(txrg.lpstrText);
- String str = charBuffer.getString();
- if (forward) {
- for(int x = 0; x < len; ++x) {
- boolean found = this.isCharInCharSet(str.charAt(x), characterSet, negate);
- if (span ? !found : found) {
- done = true;
- break;
- }
-
- ++chrg.cpMax;
- }
- } else {
- for(int x = len; x-- != 0; chrg.cpMin += -1) {
- boolean found = this.isCharInCharSet(str.charAt(x), characterSet, negate);
- if (span ? !found : found) {
- done = true;
- break;
- }
- }
- }
- }
-
- if (txrg.lpstrText != 0) {
- DllLib.freeCoTaskMem(txrg.lpstrText);
- }
-
- if (chrg.cpMin == chrg.cpMax) {
- chrg.cpMin = chrgSave.cpMin;
- chrg.cpMax = chrgSave.cpMax;
- } else if (!span) {
- if (forward) {
- chrg.cpMin = chrg.cpMax;
- } else {
- chrg.cpMax = chrg.cpMin;
- }
- }
-
- this.sendMessage(1079, 0, (CHARRANGE)chrg);
- this.sendMessage(183);
- }
- }
- }
-
- public int getBulletIndent() {
- return this.bulletIndent;
- }
-
- public void setBulletIndent(int bulletIndent) {
- this.bulletIndent = bulletIndent;
- }
-
- private void wmReflectCommand(Message m) {
- if (m.lParam == ((Control)this).getHandle()) {
- switch (Util.HIWORD(m.wParam)) {
- case 768:
- ((Control)this).onChange(Event.EMPTY);
- break;
- case 1537:
- this.onHScroll(Event.EMPTY);
- break;
- case 1538:
- this.onVScroll(Event.EMPTY);
- break;
- default:
- super.wndProc(m);
- }
- } else {
- super.wndProc(m);
- }
-
- }
-
- public int getMaxLength() {
- return this.maxLength;
- }
-
- private int getCharFormat(int mask, int effect) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int charFormat = 0;
- if (((Control)this).isHandleCreated()) {
- CHARFORMAT cf = new CHARFORMAT();
- this.sendMessage(1082, true, cf);
- if ((cf.dwMask & mask) != 0 && (cf.dwEffects & effect) != 0) {
- charFormat = 1;
- }
- }
-
- return charFormat;
- }
- }
-
- public boolean isReadOnly() {
- return (this.style & 2048) != 0;
- }
-
- public void setCharFormat(int mask, int effect, int charFormat) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- CHARFORMAT cf = new CHARFORMAT();
- cf.dwMask = mask;
- switch (charFormat) {
- case 0:
- cf.dwEffects = 0;
- break;
- case 1:
- cf.dwEffects = effect;
- break;
- default:
- throw new IllegalArgumentException("Unknown ATTRIBUTE type");
- }
-
- this.sendMessage(1092, 1, (CHARFORMAT)cf);
- }
-
- }
- }
-
- public void setMaxLength(int maxLength) {
- this.maxLength = maxLength;
- if (!((Component)this).isDesignMode() && ((Control)this).isHandleCreated()) {
- ((Control)this).sendMessage(1077, 0, maxLength == 0 ? 268435455 : maxLength);
- }
-
- }
-
- public String getSelRichText() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- return ((Control)this).isHandleCreated() ? this.streamOut(32770) : "";
- }
- }
-
- public void setSelRichText(String selRichText) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- this.streamIn(selRichText, 32770);
- }
-
- }
- }
-
- public void loadFile(String path) {
- this.loadFile(path, 0);
- }
-
- public synchronized void loadFile(String path, int fileType) {
- boolean fileLoaded = false;
- int type;
- switch (fileType) {
- case 0:
- type = 2;
- break;
- case 1:
- type = 1;
- break;
- default:
- throw new IllegalArgumentException("loadFile: invalid fileType");
- }
-
- try {
- this.bis = File.open(path);
- if (!this.bis.canSeek()) {
- throw new IllegalArgumentException("loadFile: path not a file");
- }
-
- if (type == 2) {
- String str = this.bis.getDataReader().readStringCharsAnsi("{\\rtf".length());
- if (!"{\\rtf".equals(str)) {
- throw new RuntimeException("loadFile: Invalid file format");
- }
-
- this.bis.setPosition(0L);
- }
-
- EDITSTREAM es = new EDITSTREAM();
- es.dwCookie = 0;
- es.pfnCallback = DllLib.addrOf(this.editStreamProcRoot);
- this.sendMessage(1097, type, (EDITSTREAM)es);
- ((File)this.bis).close();
- if (es.dwError != 0) {
- throw new RuntimeException("loadFile: Unable to load file");
- }
-
- this.sendMessage(185);
- fileLoaded = true;
- } finally {
- this.bis = null;
- if (fileLoaded) {
- this.fileName = path;
- if (!((Component)this).isDesignMode()) {
- this.sendMessage(186);
- }
- }
-
- }
-
- }
-
- public void addOnHScroll(EventHandler value) {
- ((Component)this).addEventHandler(EVENT_HSCROLL, value);
- }
-
- public void addOnVScroll(EventHandler value) {
- ((Component)this).addEventHandler(EVENT_VSCROLL, value);
- }
-
- public EventHandler getOnSelChange() {
- return (EventHandler)((Component)this).getEventHandler(EVENT_SELCHANGE);
- }
-
- protected void onSelChange(Event e) {
- ((Component)this).fireEvent(EVENT_SELCHANGE, e);
- }
-
- public int getRightMargin() {
- return this.rightMargin;
- }
-
- public void setRightMargin(int rightMargin) {
- if (this.rightMargin != rightMargin) {
- this.rightMargin = rightMargin;
- if (!((Component)this).isDesignMode()) {
- if (this.hDC != 0) {
- Windows.DeleteDC(this.hDC);
- }
-
- this.hDC = Windows.CreateIC("DISPLAY", (String)null, (String)null, (DEVMODE)null);
- if (((Control)this).isHandleCreated()) {
- ((Control)this).sendMessage(1096, this.hDC, rightMargin);
- }
- }
- }
-
- }
-
- public static native int DragQueryFile(int var0, int var1, StringBuffer var2, int var3);
-
- public void saveFile(String path) {
- this.saveFile(path, 0);
- }
-
- public synchronized void saveFile(String path, int fileType) {
- int type;
- switch (fileType) {
- case 0:
- type = 2;
- break;
- case 1:
- type = 1;
- break;
- default:
- throw new IllegalArgumentException("loadFile: invalid fileType");
- }
-
- try {
- this.bos = File.create(path);
- EDITSTREAM es = new EDITSTREAM();
- es.dwCookie = 1;
- es.pfnCallback = DllLib.addrOf(this.editStreamProcRoot);
- this.sendMessage(1098, type, (EDITSTREAM)es);
- ((File)this.bos).close();
- if (es.dwError != 0) {
- throw new RuntimeException("saveFile: Unable to save file.");
- }
- } finally {
- this.bos = null;
- }
-
- }
-
- public RichText() {
- synchronized(mod){}
-
- try {
- if (mod.handle == 0) {
- mod.handle = Windows.LoadLibrary("RichEd32.DLL");
- }
- } catch (Throwable var4) {
- throw var4;
- }
-
- this.editStreamProcRoot = Root.alloc(new EditStreamProc(this));
- ((Control)this).setStyle(2, false);
- ((Control)this).setTabStop(true);
- }
-
- public EventHandler getOnProtected() {
- return (EventHandler)((Component)this).getEventHandler(EVENT_PROTECTED);
- }
-
- public int getSelTabCount() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int selTabCount = 0;
- if (((Control)this).isHandleCreated()) {
- PARAFORMAT pf = new PARAFORMAT();
- this.sendMessage(1085, 0, (PARAFORMAT)pf);
- if ((16 & pf.dwMask) != 0) {
- selTabCount = pf.cTabCount;
- }
- }
-
- return selTabCount;
- }
- }
-
- protected void onProtected(Event e) {
- this.protectedError = true;
- ((Component)this).fireEvent(EVENT_PROTECTED, e);
- }
-
- public void setSelTabCount(int selTabCount) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- if (selTabCount < 0 || selTabCount > 32) {
- throw new IllegalArgumentException("SelTabCount out of range");
- }
-
- PARAFORMAT pf = new PARAFORMAT();
- this.sendMessage(1085, 0, (PARAFORMAT)pf);
- pf.dwMask = 16;
- pf.cTabCount = (short)selTabCount;
- this.sendMessage(1095, 0, (PARAFORMAT)pf);
- }
-
- }
- }
-
- protected void wndProc(Message m) {
- switch (m.msg) {
- case 135:
- super.wndProc(m);
- m.result = this.wantTabs ? m.result | 2 : m.result & -3;
- break;
- case 48206:
- this.wmReflectNotify(m);
- break;
- case 48401:
- this.wmReflectCommand(m);
- break;
- default:
- super.wndProc(m);
- }
-
- }
-
- public static native void DragAcceptFiles(int var0, boolean var1);
-
- public boolean isWantReturns() {
- return (this.style & 4096) == 0;
- }
-
- public void createControl() {
- super.createControl();
- if (((Control)this).isHandleCreated()) {
- this.setMaxLength(this.maxLength);
- ((Control)this).sendMessage(1093, 0, 3801095);
- int rm = this.rightMargin;
- this.rightMargin = 0;
- this.setRightMargin(rm);
- if (!((Component)this).isDesignMode()) {
- DragAcceptFiles(((Control)this).getHandle(), true);
- }
- }
-
- }
-
- public int getSelItalic() {
- return this.getCharFormat(2, 2);
- }
-
- public void setSelItalic(int selItalic) {
- this.setCharFormat(2, 2, selItalic);
- }
-
- public void span(String characterSet) {
- this.spanUpTo(characterSet, true, false, true);
- }
-
- public void span(String characterSet, boolean forward) {
- this.spanUpTo(characterSet, forward, false, true);
- }
-
- public void span(String characterSet, boolean forward, boolean negate) {
- this.spanUpTo(characterSet, forward, negate, true);
- }
-
- public int getScrollBars() {
- return this.scrollBars;
- }
-
- public void setScrollBars(int scrollBars) {
- if (scrollBars != 0 && scrollBars != 1 && scrollBars != 2) {
- throw new IllegalArgumentException("setScrollBars: Unknown scrollBars type");
- } else {
- if (this.scrollBars != scrollBars) {
- this.scrollBars = scrollBars;
- if (((Control)this).isHandleCreated()) {
- ((Control)this).recreateHandle();
- }
- }
-
- }
- }
-
- private synchronized String streamOut(int flags) {
- this.bos = new ByteStream();
-
- String var4;
- try {
- EDITSTREAM es = new EDITSTREAM();
- es.dwCookie = 1;
- es.pfnCallback = DllLib.addrOf(this.editStreamProcRoot);
- this.sendMessage(1098, flags, (EDITSTREAM)es);
- if (es.dwError != 0) {
- throw new RuntimeException("streamOut: Unable to get text.");
- }
-
- this.bos.setPosition(0L);
- var4 = this.bos.getDataReader().readStringCharsAnsi((int)this.bos.getLength());
- } finally {
- this.bos = null;
- }
-
- return var4;
- }
-
- public int getSelLength() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int selLength = 0;
- if (((Control)this).isHandleCreated()) {
- CHARRANGE range = new CHARRANGE();
- this.sendMessage(1076, 0, (CHARRANGE)range);
- selLength = range.cpMax - range.cpMin;
- }
-
- return selLength;
- }
- }
-
- public void setSelLength(int selLength) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- CHARRANGE range = new CHARRANGE();
- this.sendMessage(1076, 0, (CHARRANGE)range);
- range.cpMax = range.cpMin + selLength;
- this.sendMessage(1079, 0, (CHARRANGE)range);
- this.sendMessage(183);
- }
-
- }
- }
-
- public String getRichText() {
- return ((Control)this).isHandleCreated() ? this.streamOut(2) : "";
- }
-
- public String getSelText() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- return ((Control)this).isHandleCreated() ? this.streamOut(32769) : "";
- }
- }
-
- public void setRichText(String richText) {
- if (((Control)this).isHandleCreated()) {
- this.streamIn(richText, 2);
- }
-
- }
-
- public void setSelText(String selText) {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- if (((Control)this).isHandleCreated()) {
- }
-
- }
- }
-
- private synchronized void streamIn(String string, int flags) {
- if (string.length() == 0) {
- if (('ΦÇÇ' & flags) != 0) {
- this.sendMessage(771);
- this.protectedError = false;
- } else {
- ((Control)this).sendMessage(12, 0, "");
- }
- } else {
- if ((flags & 'ΦÇÇ') == 0) {
- CHARRANGE cr = new CHARRANGE();
- this.sendMessage(1079, 0, (CHARRANGE)cr);
- }
-
- try {
- this.bis = new ByteStream();
- this.bis.getDataWriter().writeStringCharsAnsi(string);
- this.bis.setPosition(0L);
- EDITSTREAM es = new EDITSTREAM();
- es.dwCookie = 0;
- es.pfnCallback = DllLib.addrOf(this.editStreamProcRoot);
- this.sendMessage(1097, flags, (EDITSTREAM)es);
- if (!this.isProtectedError()) {
- if (es.dwError != 0) {
- throw new RuntimeException("streamIn: Unable to load text");
- }
-
- if (!((Component)this).isDesignMode()) {
- this.sendMessage(186);
- }
-
- return;
- }
- } finally {
- this.bis = null;
- }
-
- }
- }
-
- public void finalize() {
- if (this.editStreamProcRoot != 0) {
- Root.free(this.editStreamProcRoot);
- }
-
- }
-
- public String getText() {
- return ((Control)this).isHandleCreated() ? this.streamOut(1) : new String("");
- }
-
- public int getSelStart() {
- if (((Component)this).isDesignMode()) {
- throw new RuntimeException("Not supported at Design time");
- } else {
- int selStart = 0;
- if (((Control)this).isHandleCreated()) {
- CHARRANGE range = new CHARRANGE();
- this.sendMessage(1076, 0, (CHARRANGE)range);
- selStart = range.cpMin;
- }
-
- return selStart;
- }
- }
- }
-